package game;


import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;

public class FactoriaImagenes {

	private ImageObserver observer;
	private PintarLienzo plienzo;

	public FactoriaImagenes(ImageObserver observer) {
		this.observer = observer;
		plienzo = new PintarLienzo(observer);
	}

	public Image generarImagenFondo() {
		Image imagen = new BufferedImage(600, 400, BufferedImage.TYPE_INT_ARGB);
		Graphics g = imagen.getGraphics();

		for (int n = 0; n < 200; n++) {
			g.setColor(new Color(255, 255 - n / 2, 128 - n / 2));
			g.fillRect(0, n * 2, 600, 2);
		}

		for (int n = 100; n > 0; n--) {
			g.setColor(new Color(128 - n, 255 - n, 128 - n));
			g.fillOval(n, n / 4, n * 5, n * 6);
		}

		g.setColor(Color.black);
		g.fillRect(325, 50, 50, 50);
		g.fillRect(0, 0, 110, 400);

		for (int n = -100; n <= 100; n++) {
			if (n < -80 || n > 80)
				g.setColor(Color.black);
			else
				g.setColor(new Color(255, 200, 128));
			plienzo.pintaLinea2D(g, n, -100, n, 100);
			plienzo.pintaLinea3D(g, n, -100, n, 100);
		}

		int x, y1, y2;
		for (int n = 0; n < 100; n++) {
			x = ((int) (Math.random() * 161 - 80));
			y1 = ((int) (Math.random() * 201 - 100));
			y2 = ((int) (Math.random() * 201 - 100));
			g.setColor(new Color(255 - n / 5, 200 - n / 2, 128 - n));
			plienzo.pintaLinea2D(g, x, y1, x, y2);
			plienzo.pintaLinea3D(g, x, y1, x, y2);
		}

		g.setColor(new Color(128, 100, 100));
		for (int n = -80; n <= 80; n += 20) {
			plienzo.pintaLinea2D(g, n, -100, n, 100);
			plienzo.pintaLinea3D(g, n, -100, n, 100);
		}

		return imagen;
	}

	public Image generarImagenBolo() {
		Image imagen = new BufferedImage(20, 40, BufferedImage.TYPE_INT_ARGB);
		Graphics g = imagen.getGraphics();
		int x1[] = { 0, 10, 20 };
		int y1[] = { 40, 10, 40 };
		for (int n = 0; n < 5; n++) {
			g.setColor(new Color(n * 40, 128 + n * 20, 255));
			g.fillPolygon(x1, y1, 3);
			x1[0] += 2;
			x1[2]--;
		}
		plienzo.pintaCabezaBolo(g, 0, 0);
		return imagen;
	}

	public Image[] generarImagenBoloTumbado3D() {
		int nFotogramas = 16;
		Image imagenes[] = new Image[nFotogramas];
		Graphics g[] = new Graphics[nFotogramas];
		for (int n = 0; n < imagenes.length; n++) {
			// imagenes[n]=new BufferedImage(80,20,
			// BufferedImage.TYPE_INT_ARGB);
			imagenes[n] = Toolkit.getDefaultToolkit().getImage(
					"imagenes/pinTumbado.png");
			// g[n]=imagenes[n].getGraphics();
		}
		/*
		 * int x[]={0,0,0,0}; int y[]={12,8,0,20}; int xC[], yC[]; double
		 * nAngulo; double xRel, yRel; for (int n=0;n<nFotogramas;n++){
		 * nAngulo=(2*Math.PI)*n/nFotogramas; xRel=Math.cos(nAngulo);
		 * yRel=Math.sin(nAngulo);
		 * 
		 * //if (yRel>=0) //plienzo.pintaCabezaBolo(g[n],30,0);
		 * xC=(int[])x.clone(); yC=(int[])y.clone();
		 * xC[0]=xC[1]=(int)(40+xRel*5); xC[2]=xC[3]=(int)(40+xRel*30); /*for
		 * (int m=0;m<5;m++){ g[n].setColor(new Color(m*40,128+m*20,255));
		 * g[n].fillPolygon(xC, yC, 4); yC[0]--; yC[1]++; yC[2]+=2; yC[3]--; }
		 * if (yRel<0) plienzo.pintaCabezaBolo(g[n],30,0); else{
		 * g[n].setColor(Color.blue); g[n].fillOval((int)(xC[2]-yRel*10), y[2],
		 * (int)(yRel*20), 20); }
		 */
		// }
		return imagenes;
	}

}
